module ExitStrategyTest

open System.Reactive.Linq
open Xunit
open Xunit.FSharp
open com.ib.client 
open Trading.IBApi

[<Fact>]
let stopLossNeverFired() = 
    //ARRANGE
    let position = { Contract = Contract(); Size = 4; Cost = 200. }
    let lossLimitPct = 20.
    let priceTicks = 
        fun contract -> 
            assert (contract = position.Contract)
            [| 45.; 41.; |].ToObservable()
    //ACT
    let result = ExitStrategy.stopLoss position priceTicks lossLimitPct |> Observable.ToEnumerable 
    let x = result |> Seq.toArray
    //ASSERT
    result |> should be Empty

[<Fact>]
let stopLossFired() = 
    //ARRANGE
    let position = { Contract = Contract(); Size = 4; Cost = 200. }
    let lossLimitPct = 20.
    let priceTicks = 
        fun contract -> 
            assert (contract = position.Contract)
            [| 45.; 39.; |].ToObservable()
    //ACT
    let result = 
        ExitStrategy.stopLoss position priceTicks lossLimitPct 
        |> Observable.ToEnumerable
        |> Seq.toArray
    //ASSERT
    result |> should equal [|position|] 



